<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr = ["red", "yellow", "green", "white", "black", "purple", "pink", "blue", "skyblue", "deeppink"];

    // function getRandomName() {
    //   let random = Math.floor(Math.random() * arr.length);
    //   return arr[random];
    // }
    // alert(getRandomName());

    // 随机点名但是不重复出现  .pop .shift .splice都可以删除数组元素，但只有.splice可以根据数组下标精确删除数组元素
    // .splice(起始位置，删除元素个数)
    function getRandomName() {
      let random = Math.floor(Math.random() * arr.length);
      return random;
    }
    document.write(arr.splice(getRandomName(), 1));
    console.log(arr);
  </script>
</body>

</html>